﻿using System.Data;
using EntitiesTM;
using System.Data.SqlClient;

namespace DataAccess
{
    public class DaClient
    {
        public DataTable selAllClient(string companyid)
        {
            string strCommandText = "selAllClient"+companyid;
            return SqlHelper.ExecuteData(CommandType.StoredProcedure, strCommandText, null);
        }

        public DataTable selClientByID(int clientID, string companyid)
        {
            string strCommandText = "selClientByID" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[1];
            paraLocal[0] = new SqlParameter("@ClientID", clientID);
            return SqlHelper.ExecuteData(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public void insClient(EnClient client, string companyid)
        {
            string strCommandText = "insClient" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[9];
            paraLocal[0] = new SqlParameter("@ClientName", client.clientName);
            paraLocal[1] = new SqlParameter("@ClientDescription", client.clientDes);
            paraLocal[2] = new SqlParameter("@ClientAddress", client.clientAddress);
            paraLocal[3] = new SqlParameter("@ClientNameContactPerson", client.contactPerson);
            paraLocal[4] = new SqlParameter("@ClientURL", client.url);
            paraLocal[5] = new SqlParameter("@ClientNameAlt", client.nameAlt);
            paraLocal[6] = new SqlParameter("@ClientPhoneContactPerson", client.phone);
            paraLocal[7] = new SqlParameter("@ClientEmailContactPerson", client.email);
            paraLocal[8] = new SqlParameter("@ClientFaxContactPerson", client.fax);

            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }
        public void updClient(EnClient client, string companyid)
        {
            string strCommandText = "updClient" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[10];
            paraLocal[0] = new SqlParameter("@ClientName", client.clientName);
            paraLocal[1] = new SqlParameter("@ClientDescription", client.clientDes);
            paraLocal[2] = new SqlParameter("@ClientAddress", client.clientAddress);
            paraLocal[3] = new SqlParameter("@ClientNameContactPerson", client.contactPerson);
            paraLocal[4] = new SqlParameter("@ClientURL", client.url);
            paraLocal[5] = new SqlParameter("@ClientNameAlt", client.nameAlt);
            paraLocal[6] = new SqlParameter("@ClientPhoneContactPerson", client.phone);
            paraLocal[7] = new SqlParameter("@ClientEmailContactPerson", client.email);
            paraLocal[8] = new SqlParameter("@ClientFaxContactPerson", client.fax);
            paraLocal[9] = new SqlParameter("@ClientID", client.clientID);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }

        public void delClient(int clientID, string companyid)
        {
            string strCommandText = "delClient" + companyid;
            SqlParameter[] paraLocal = new SqlParameter[1];
            paraLocal[0] = new SqlParameter("@ClientID", clientID);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, strCommandText, paraLocal);
        }
    }
}
